
// 通过升幂再降幂解决浮点数精度问题，有的数升幂到整数之后还是会出现最小精度（比如2.22），所以最后结果通过toFixed方法得到相应的值（要求精确的需求考虑引入开源库。。，例如：number-precision）
let addNum = (list) => {
  if (!list || list.length === 0) return 0
  let digitList = []
  for (let i = 0; i < list.length; i++) {
    let item = list[i].toString()
    let l = item.split('.')
    l[1] && digitList.push(l[1].length)
  }
  let maxDigit = digitList.length > 0 ? Math.max.apply(null, digitList) : 0
  // add by reduce
  let intAdd = list.map(item => {
    return (item.toString()) * Math.pow(10, maxDigit)
  }).reduce((prev, curr) => {
    return prev + curr
  })
  return (intAdd / Math.pow(10, maxDigit)).toFixed(maxDigit)
  
  // add by eval
  /* let intList = list.map(item => {
    return (item.toString()) * Math.pow(10, maxDigit)
  })
  return eval(intList.join('+')) / Math.pow(10, maxDigit) */
}
// 数组对象合并相同属性的value值，并去重
let concatSameKey = (list) => {
  if (!list || list.length === 0) return
  return list.map((item, index, arr) => {
    let _item = arr.find(iitem => iitem.key === item.key)
    if (_item === item) {
      _item.value = [item.value]
      return _item
    } else {
      _item.value.push(item.value)
      return null
    }
  }).filter(item => item !== null)
}

// 数字字符串数组转数字数组 ['1', '2', '3'] => [1,2,3]
let stringToNumberInArray1 = (arr) => {
  return arr.map(Number)
}
let stringToNumberInArray2 = (arr) => {
  return JSON.parse('[' + String(arr) + ']')
}
var c = ['1', '2', '3']

console.log(stringToNumberInArray2(c))
console.log([1,2].map(String))